package com.party.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.party.business.domain.TFjFile;
import com.party.business.service.ITFjFileService;
import com.party.common.annotation.DataScope;
import com.party.common.annotation.DataSource;
import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.core.page.TableDataInfo;
import com.party.common.enums.BusinessType;
import com.party.common.enums.DataSourceType;
import com.party.common.utils.poi.ExcelUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.business.domain.SecurityIncidents;
import com.party.business.service.ISecurityIncidentsService;

/**
 * 安全事件Controller
 *
 * @author ruoyi
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/business/securityincidents")
public class SecurityIncidentsController extends BaseController {
    @Autowired
    private ISecurityIncidentsService securityIncidentsService;

    @Autowired
    private ITFjFileService tFjFileService;

    /**
     * 查询安全事件列表
     */
//@RequiresPermissions("business:securityincidents:list")
    @GetMapping("/list")
    @DataSource(value = DataSourceType.SLAVE)
    public TableDataInfo list(SecurityIncidents securityIncidents) {
        startPage();
        List<SecurityIncidents> list = securityIncidentsService.selectSecurityIncidentsList(securityIncidents);
        return getDataTable(list);
    }

    /**
     * 导出安全事件列表
     */
    //@RequiresPermissions("business:securityincidents:export")
    @Log(title = "安全事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SecurityIncidents securityIncidents) {
        List<SecurityIncidents> list = securityIncidentsService.selectSecurityIncidentsList(securityIncidents);
        ExcelUtil<SecurityIncidents> util = new ExcelUtil<SecurityIncidents>(SecurityIncidents.class);
        util.exportExcel(response, list, "安全事件数据");
    }

    /**
     * 获取安全事件详细信息
     */
    //@RequiresPermissions("business:securityincidents:query")
    @DataSource(value = DataSourceType.SLAVE)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        SecurityIncidents byId = securityIncidentsService.getById(id);
        return AjaxResult.success(byId);
    }

    /**
     * 新增安全事件
     */
    //@RequiresPermissions("business:securityincidents:add")
    @Log(title = "安全事件", businessType = BusinessType.INSERT)
    @PostMapping
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult add(@RequestBody SecurityIncidents securityIncidents) {
        securityIncidentsService.save(securityIncidents);
        return AjaxResult.success();
    }

    /**
     * 修改安全事件
     */
    //@RequiresPermissions("business:securityincidents:edit")
    @Log(title = "安全事件", businessType = BusinessType.UPDATE)
    @PutMapping
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult edit(@RequestBody SecurityIncidents securityIncidents) {
        SecurityIncidents securityIncidents1 = securityIncidentsService.selectSecurityIncidentsById(securityIncidents.getId());
        if(securityIncidents1==null){
            securityIncidentsService.save(securityIncidents1);
        }else{
            securityIncidentsService.updateById(securityIncidents);
        }
        return success();
    }

    /**
     * 删除安全事件
     */
    //@RequiresPermissions("business:securityincidents:remove")
    @Log(title = "安全事件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(securityIncidentsService.removeByIds(Arrays.asList(ids)));
    }
}
